#include <iostream>
#include <list>
#include <mutex>
#include <algorithm>

using namespace std;

//但大多数情况下，互斥量通常会与需要保护的数据放在同一类中，而不是
//定义成全局变量。这是面向对象设计的准则
list<int> some_list;
mutex some_mutex;

void add_to_list(int new_value)
{
    lock_guard<mutex> guard(some_mutex);
    some_list.push_back(new_value);
}

bool list_contains(int value_to_find)
{
    lock_guard<mutex> guard(some_mutex);
    return find(some_list.begin(), some_list.end(), value_to_find) 
        != some_list.end();
}

//in C++17 lock_guard get new characteristic
//lock_guard become template class
//compile can pass but compiler will alert
lock_guard guard(some_mutex); //is legal

//in C++17 also get another new characteristic
//scoped_lock is one of boost sercurity lock_guard
//compile can pass but compiler will alert
scoped_lock guard1(some_mutex); //is legal

int main()
{
    return 0;
}

